package com.liuhongwei.test.entity.query;

import org.apache.commons.lang.StringUtils;

import java.util.Date;

public class PageQuery {

    //当前页
    public Integer currentPage = 1;

    // 页大小,界面传递过来的页大小
    public Integer pageSize = 10;

    // 页大小,最终SQL使用的页大小
    // 1.pageSize判断之后的大小,最大100
    // 2.内部代码需要的实际页大小
    public Integer pageSizeInner = 10;

    //创建开始时间
    public Date createTimeBegin;

    //创建结束时间
    public Date createTimeEnd;

    //排序
    public String orderBy;

    public Integer getCurrentPage() {
        return currentPage;
    }

    public void setCurrentPage(Integer currentPage) {
        this.currentPage = currentPage;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;

        if (this.pageSize > 100 || this.pageSize <= 0) {
            this.pageSize = 100;
        }

        this.setPageSizeInner(this.pageSize);
    }

    public Integer getPageSizeInner() {
        return pageSizeInner;
    }

    public void setPageSizeInner(Integer pageSizeInner) {
        this.pageSizeInner = pageSizeInner;
    }

    public Date getCreateTimeBegin() {
        return createTimeBegin;
    }

    public void setCreateTimeBegin(Date createTimeBegin) {
        this.createTimeBegin = createTimeBegin;
    }

    public Date getCreateTimeEnd() {
        return createTimeEnd;
    }

    public void setCreateTimeEnd(Date createTimeEnd) {
        this.createTimeEnd = createTimeEnd;
    }

    public String getOrderBy() {
        if(StringUtils.isEmpty(orderBy)) {
            return "create_time desc";
        }
        return orderBy;
    }

    public void setOrderBy(String orderBy) {
        this.orderBy = orderBy;
    }

    public int getStartPosition() {
        //不要使用pageSize pageSize在设置很大的时候默认为100导致这里出错
        return (currentPage - 1) * pageSizeInner;
    }


}
